package org.monkey.request.plugin.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.monkey.common.constant.config.CommonConstant;
import org.monkey.request.plugin.entity.TimeAnalyse;

@Aspect
@Slf4j
public class TimeAnalyseAspect {


  @Around(value = "@annotation(timeAnalyse)")
  public Object doAround(ProceedingJoinPoint point, TimeAnalyse timeAnalyse) throws Throwable {
    long l1 = System.currentTimeMillis();
    String tag = CommonConstant.EMPTY_STRING;
    if (timeAnalyse != null) {
      tag = timeAnalyse.tag();
    }
    try {
      return point.proceed();
    } finally {
      log.info("tag:{},method={},during:{} ms", tag, point.getSignature().getName(),
          System.currentTimeMillis() - l1);
    }

  }
}
